package com.szwistar.common.jnlua;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.naef.jnlua.LuaState;
import com.naef.jnlua.NamedJavaFunction;

public class LuaUtils {
	static final Logger LOG = LoggerFactory.getLogger(LuaUtils.class);

	static LuaUtils INSTANCE;
	private LuaUtils() {}

	public static LuaUtils instance() {
		if( INSTANCE == null ) {
			INSTANCE = new LuaUtils();
		}
		return INSTANCE;
	}

	/// 获取当前时间: 1970年1月1日到现在的毫秒数
	protected static class JLFunc_currentTimeMillis implements NamedJavaFunction {
        @Override
        public String getName() { return "currentTimeMillis"; }

        @Override
        public int invoke(LuaState luaState) {
        	luaState.pushNumber(System.currentTimeMillis());
            return 1;
        }
    }

	public boolean init(LuaState luaState) {
		// Register lua functions
        luaState.register(new JLFunc_currentTimeMillis());
        return true;
	}
}
